Fix for issue 48: JSONValue.parse does not correctly decode UTF-8 bytes from an inputstream#1
Open
johnrevill wants to merge 4 commits intonetplex:masterfrom
Open
Fix for issue 48: JSONValue.parse does not correctly decode UTF-8 bytes from an inputstream#1johnrevill wants to merge 4 commits intonetplex:masterfrom
johnrevill wants to merge 4 commits intonetplex:masterfrom
Conversation
decode UTF-8 bytes from an inputstream", https://code.google.com/p/json-smart/issues/detail?id=48)
from an inputstream", https://code.google.com/p/json-smart/issues/detail?id=48). Instead of taking a byte at a time from the InputStream, this now wraps the InputStream in an InputStreamReader and uses the existing JSONParserReader to read one character at a time. A few extra parse() methods were added to take the source bytes' character set as a parameter. This allows for cases when the platform's default character set is not wanted.
davydsantos
reviewed
Jun 11, 2024
| c = (char) i; | ||
| pos++; | ||
| } | ||
| return super.parse(new InputStreamReader(in)); |
There was a problem hiding this comment.
Should this use the params instead of ignoring what is passed in?
Suggested change
| return super.parse(new InputStreamReader(in)); | |
| return super.parse(new InputStreamReader(in), containerFactory, handler); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here's a possible fix for issue 48 (https://code.google.com/p/json-smart/issues/detail?id=48).
The problem seemed to be that the parsing for InputStreams was taking a byte at a time from the InputStream and considering that byte to be a character. This causes some strangeness when parsing UTF characters beyond the usual ascii range.
The changes are confined to just the JSONParserInputStream class. Instead of using the InputStream directly, it now wraps it in a InputStreamReader (http://docs.oracle.com/javase/7/docs/api/java/io/InputStreamReader.html) which deals with multi-byte characters. As a side effect of wrapping it up in a Reader, the JSONParserReader can be used instead, which is why the class now extends JSONParserReader.
Hope this helps.
I'm less familiar with json-smart-v2, but could have a go at fixing the issue in that version too if you want.